//
//  General_knowledge_Table_Cell.m
//  Food
//
//  Created by dllo on 15/7/18.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "General_knowledge_Table_Cell.h"
#import "BaseHeader.h"
#import "UIImageView+WebCache.h"
@implementation General_knowledge_Table_Cell

- (void)dealloc
{
    [_imageview release];
    [_introduceLable release];
    [_lineLable release];
    [_makeMethodTitleLabel release];
    [_maleMethodContentLable release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.imageview = [[UIImageView alloc] init];
        [self.contentView addSubview:self.imageview];
        
        self.introduceLable = [[UILabel alloc] init];
        self.introduceLable.numberOfLines = 0;
        [self.contentView addSubview:self.introduceLable];
        
        self.lineLable = [[UILabel alloc] init];
        [self.lineLable setTextAlignment:NSTextAlignmentCenter];
        self.lineLable.text = @"---------------------------------------";
        [self.contentView addSubview:self.lineLable];
        
        self.makeMethodTitleLabel = [[UILabel alloc] init];
        self.makeMethodTitleLabel.text = @"制作方法";
        [self.makeMethodTitleLabel setTextAlignment:NSTextAlignmentCenter];
        self.makeMethodTitleLabel.backgroundColor = [UIColor orangeColor];
        [self.contentView addSubview:self.makeMethodTitleLabel];
        
        self.maleMethodContentLable = [[UILabel alloc] init];
        self.maleMethodContentLable.numberOfLines = 0;
        [self.contentView addSubview:self.maleMethodContentLable];
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    self.imageview.frame = CGRectMake(20, 20, ScreenWidth - 40, 200);
    
    self.introduceLable.frame = CGRectMake(20, self.imageview.frame.origin.y * 2 + self.imageview.frame.size.height, ScreenWidth - 40, [[self class] heightwithText:self.introduceLable.text]);
    
    self.lineLable.frame = CGRectMake(20, 10 + self.introduceLable.frame.origin.y + self.introduceLable.frame.size.height, ScreenWidth - 40, 30);
    
    self.makeMethodTitleLabel.frame = CGRectMake(20, self.lineLable.frame.origin.y + self.lineLable.frame.size.height + 10, 80, 30);
    
    self.maleMethodContentLable.frame = CGRectMake(20, self.makeMethodTitleLabel.frame.origin.y + self.makeMethodTitleLabel.frame.size.height + 10, ScreenWidth - 40, [[self class] heightwithText:self.maleMethodContentLable.text]);
}

+ (CGFloat) heightwithText:(NSString *) text
{
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:17]};
    CGSize size = CGSizeMake(ScreenWidth - 40, 1000);
    CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.height;
}

- (void)setModel:(General_knowledge_Model *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    [self.imageview sd_setImageWithURL:[NSURL URLWithString:model.imagePath]];
    NSString *str1 = [NSString stringWithFormat:@"       %@", model.nutritionAnalysis];
    self.introduceLable.text = str1;
    NSString *str2 = [NSString stringWithFormat:@"       %@", model.productionDirection];
    self.maleMethodContentLable.text = str2;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
